<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>模拟一个数据监测</title>
  <script src="../js/vue.js"></script>
</head>
<body>
   <div id="root">
    
   

   </div>
    <script type='text/javascript'>
     
     let data = {
        name:'周杰',
        age:18
     }

     const obs = new Observer(data)
     let vm = {}
    // (2) vm._data 数据代理 obs ，结论在上一个html
     vm._data = obs
    
    // (1) 构造函数 obs 数据代理 data
     function Observer(obj){
         const keys = Object.keys(obj)
         keys.forEach((k)=>{
             Object.defineProperty(this,k,{
                get(){
                   return obj[k]
                },
                set(val){
                  obj[k] = val
                }
             })
         })
     }


        new Vue({
            el:'#root',
            data:{
              persons:[
                {id:1, name:'马冬梅', age:18, sex:"女"},
                {id:2, name:'周冬雨', age:10, sex:"女"},
                {id:3, name:'周杰伦', age:28, sex:"男"},
                {id:4, name:'温兆伦', age:21, sex:"男"}
              ]
            }
        })
    </script>
</body>
</html>